package com.gouaixin.bee.beeframework2.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.adapter.E1_GiftShopAdapter;
import com.gouaixin.bee.beeframework2.bean.Gift;
import com.gouaixin.bee.beeframework2.model.DialogModel;
import com.gouaixin.bee.beeframework2.tool.mLog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/4/23.
 */
//礼物商城界面
public class E1_GiftShopActivity extends Activity {
    Context context = E1_GiftShopActivity.this;

    //搜索、赠送、充值
    TextView search, handsel, rechange;

    //数量、名字
    TextView number, name;

    //竖向选项卡
    TextView tab01, tab02, tab03, tab04, tab05, tab06;
    TextView[] tabs;

    //网格视图
    GridView gridview;
    E1_GiftShopAdapter adapter;
    List<Gift> currentDatas;

    //礼物的本地资源配置

    List<Gift> datas01;
    List<Gift> datas02;
    List<Gift> datas03;
    List<Gift> datas04;
    List<Gift> datas05;
    List<Gift> datas06;
    List<List<Gift>> datas;


//    String[] nameArray03=new String[]{""};
//    int[] iconArray03 = new int[]{R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001, R.drawable.gift03001};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.e1_giftshop);

        initData();

        initUser();

        initView();

        initIntent();

        setListener();

    }

    /**
     * 根据传入的Intent设置数据
     */
    private void initIntent() {
        Intent it=getIntent();
        String jname=it.getStringExtra("jname");
        name.setText(jname);
    }

    /**
     * 读取网络的user数据
     */
    private void initUser() {

    }

    /**
     * 准备本地的礼物数据
     */
    private void initData() {
        int[] iconArray01={R.drawable.gift01001,R.drawable.gift01002,R.drawable.gift01003,R.drawable.gift01004,R.drawable.gift01005,R.drawable.gift01006,R.drawable.gift01007,R.drawable.gift01008,R.drawable.gift01009,R.drawable.gift01010,R.drawable.gift01011,R.drawable.gift01012};
        String[] nameArray01={"海洋之星","无敌大黄蜂","mini cooper","宝马","奔驰","莲花跑车","法拉利","兰博基尼","保时捷911","劳斯莱斯","布加迪威航","法拉利游艇"};
        String[] priceArray01={"3000","5000","3000","3000","4000","3000","5000","3000","3000","9000","8000","10000"};
        datas01 = new ArrayList<Gift>();
        for (int i = 0; i < iconArray01.length; i++) {
            Gift bean = new Gift();
            bean.setIcon(iconArray01[i]);
            bean.setName(nameArray01[i]);
            bean.setPrice(priceArray01[i]);
            datas01.add(bean);
        }

        int[] iconArray02={R.drawable.gift0200102,R.drawable.gift02002,R.drawable.gift02003,R.drawable.gift02004,R.drawable.gift02005,R.drawable.gift02006,R.drawable.gift02007,R.drawable.gift02008,R.drawable.gift02009,R.drawable.gift02010,R.drawable.gift02011,R.drawable.gift02012};
        String[] nameArray02={"丘比特之箭","烛光晚餐","夏威夷之旅","生日快乐","爱敦阁别墅","烟火的季节","樱花海","豪华婚礼","萨菲拉度拉岛","环游世界","天尊庇佑","爱的火箭"};
        String[] priceArray02={"8000","10000","10000","10000","15000","15000","15000","25000","25000","9000","25000","25000"};
        datas02 = new ArrayList<Gift>();
        for (int i = 0; i < iconArray01.length; i++) {
            Gift bean = new Gift();
            bean.setIcon(iconArray02[i]);
            bean.setName(nameArray02[i]);
            bean.setPrice(priceArray02[i]);
            datas02.add(bean);
        }

        int[] iconArray03={R.drawable.gift0300102,R.drawable.gift03002,R.drawable.gift03003,R.drawable.gift03004,R.drawable.gift03005,R.drawable.gift03006,R.drawable.gift03007,R.drawable.gift03008,R.drawable.gift03009,R.drawable.gift03010};
        String[] nameArray03={"踢踏舞","hip hop","钢管舞","欢乐舞","旋转芭蕾","草裙舞","肚皮舞","nobody","太空步","探戈"};
        String[] priceArray03={"5000","5000","6000","10000","15000","15000","8000","50000","25000","9000"};
        datas03 = new ArrayList<Gift>();
        for (int i = 0; i < iconArray03.length; i++) {
            Gift bean = new Gift();
            bean.setIcon(iconArray03[i]);
            bean.setName(nameArray03[i]);
            bean.setPrice(priceArray03[i]);
            datas03.add(bean);
        }

        int[] iconArray04={R.drawable.gift0400102,R.drawable.gift04002,R.drawable.gift04003,R.drawable.gift04004,R.drawable.gift04005,R.drawable.gift04006,R.drawable.gift04007,R.drawable.gift04008,R.drawable.gift04009};
        String[] nameArray04={"管理福利","h幸运百合","幸运豆","平安符","四叶草","燕子","摩天轮","财神","幸运星"};
        String[] priceArray04={"5000","1000","2000","5000","3000","3000","7000","8000","6000"};
        datas04 = new ArrayList<Gift>();
        for (int i = 0; i < iconArray04.length; i++) {
            Gift bean = new Gift();
            bean.setIcon(iconArray04[i]);
            bean.setName(nameArray04[i]);
            bean.setPrice(priceArray04[i]);
            datas04.add(bean);
        }

        int[] iconArray05={R.drawable.gift0500102,R.drawable.gift05002,R.drawable.gift05003,R.drawable.gift05004,R.drawable.gift05005,R.drawable.gift05006,R.drawable.gift05007,R.drawable.gift05008,R.drawable.gift05009,R.drawable.gift05010,R.drawable.gift05011,R.drawable.gift05012};
        String[] nameArray05={"缘定今生","我们约会吧","玫瑰海洋","普天重庆","旅行婚礼","烟火的季节","豪华车队","烟花庆典","财源滚滚","真情告白","星币轰炸机","飞机守护队"};
        String[] priceArray05={"52000","15000","20000","52000","15000","15000","88800","100000","25000","9000","25000","25000"};
        datas05 = new ArrayList<Gift>();
        for (int i = 0; i < iconArray05.length; i++) {
            Gift bean = new Gift();
            bean.setIcon(iconArray05[i]);
            bean.setName(nameArray05[i]);
            bean.setPrice(priceArray05[i]);
            datas05.add(bean);
        }

        int[] iconArray06={R.drawable.gift06001,R.drawable.gift06002,R.drawable.gift06003,R.drawable.gift06004,R.drawable.gift06005,R.drawable.gift06006,R.drawable.gift06007,R.drawable.gift06008,R.drawable.gift06009,R.drawable.gift06010};
        String[] nameArray06={"屁屁王","就要你了","感动","年度最佳艺人","晚安","走你","扔鸡蛋","江南style","屏幕炸弹","便便"};
        String[] priceArray06={"4000","1000","1000","2000","4000","3000","5000","3000","3000","9000"};
        datas06 = new ArrayList<Gift>();
        for (int i = 0; i < iconArray06.length; i++) {
            Gift bean = new Gift();
            bean.setIcon(iconArray06[i]);
            bean.setName(nameArray06[i]);
            bean.setPrice(priceArray06[i]);
            datas06.add(bean);
        }

        mLog.e("准备本地的礼物数据:完成");
    }

    /**
     * 设置监听
     */
    private void setListener() {
        for (int i = 0; i < tabs.length; i++) {
            final int finalI = i;
            tabs[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setTabBackground(finalI);
                    refreshDatas(finalI);
                }
            });
        }

        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                AbToastUtil.showToast(context, "你点击了：" + position);
                if(position<currentDatas.size()){
                    String nameStr=currentDatas.get(position).getName();
                    number.setText(nameStr);
                }
            }
        });

        rechange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                AbToastUtil.showToast(context, "你点击了：" + "充值");
                Intent it=new Intent(context,B13_aiBiActivity.class);
                startActivity(it);
                finish();
            }
        });

        handsel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                AbToastUtil.showToast(context, "你点击了：" + "赠送");
                DialogModel.goAibi(context, "你的爱币余额不足，请充值后再赠送！");
            }
        });

        mLog.e("设置监听:完成=1");
    }

    /**
     * 设置GridView的数据
     *
     * @param finalI
     */
    private void refreshDatas(int finalI) {
        mLog.e("设置GridView的数据:完成=1");
        switch (finalI) {
            case 0:
                currentDatas=datas01;
                adapter.setData(currentDatas, gridview.getNumColumns());
                adapter.notifyDataSetChanged();
                break;
            case 1:
                currentDatas=datas02;
                adapter.setData(currentDatas, gridview.getNumColumns());
                adapter.notifyDataSetChanged();
                break;
            case 2:
                currentDatas=datas03;
                adapter.setData(currentDatas, gridview.getNumColumns());
                adapter.notifyDataSetChanged();
                break;
            case 3:
                currentDatas=datas04;
                adapter.setData(currentDatas, gridview.getNumColumns());
                adapter.notifyDataSetChanged();
                break;
            case 4:
                currentDatas=datas05;
                adapter.setData(currentDatas, gridview.getNumColumns());
                adapter.notifyDataSetChanged();
                break;
            case 5:
                currentDatas=datas06;
                adapter.setData(currentDatas, gridview.getNumColumns());
                adapter.notifyDataSetChanged();
                break;
        }
        mLog.e("设置GridView的数据:完成=2");
    }

    /**
     * 设置选项卡的背景
     *
     * @param finalI
     */
    private void setTabBackground(int finalI) {
        for (int i = 0; i < tabs.length; i++) {
            if (i == finalI) {
                tabs[i].setBackgroundResource(R.drawable.corner_view_red);
            } else {
                tabs[i].setBackgroundDrawable(null);
            }
        }
    }


    /**
     * 准备视图
     */
    private void initView() {
        search = (TextView) findViewById(R.id.header_right);
        handsel = (TextView) findViewById(R.id.footer_right);
        rechange = (TextView) findViewById(R.id.recharge);

        number = (TextView) findViewById(R.id.footer_number);
        name = (TextView) findViewById(R.id.footer_name);

        tab01 = (TextView) findViewById(R.id.tab01);
        tab02 = (TextView) findViewById(R.id.tab02);
        tab03 = (TextView) findViewById(R.id.tab03);
        tab04 = (TextView) findViewById(R.id.tab04);
        tab05 = (TextView) findViewById(R.id.tab05);
        tab06 = (TextView) findViewById(R.id.tab06);
        tabs = new TextView[]{tab01, tab02, tab03, tab04, tab05, tab06};

        mLog.e("准备视图:完成=1");


        gridview = (GridView) findViewById(R.id.gridview);
        adapter = new E1_GiftShopAdapter(context);
        currentDatas=datas01;
        adapter.setData(currentDatas,gridview.getNumColumns());
        gridview.setAdapter(adapter);

        mLog.e("绑定GV:完成=1");
    }
}
